package com.tsxy.mapper;

import com.tsxy.controller.dto.BookDto;
import com.tsxy.entity.UsedBook;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 飞
 * @since 2022-03-12
 */
@Mapper
public interface UsedBookMapper extends BaseMapper<UsedBook> {

    @Select({"<script>" +
            "select * from used_book" +
            "<where>" +
            "<if test = 'name != null'>" +
            " name like #{name} " +
            "</if>" +
            "<if test = 'author != null'>" +
            " AND author like #{author} " +
            "</if>" +
            "</where>" +
            " order by id desc" +
            " limit #{begin} , #{size}" +
            "</script>"
    })
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "book_sort_id",property = "bookSortId"),
            @Result(column = "name",property = "name"),
            @Result(column = "dscp",property = "dscp"),
            @Result(column = "price",property = "price"),
            @Result(column = "version",property = "version"),
            @Result(column = "color",property = "color"),
            @Result(column = "suit",property = "suit"),
            @Result(column = "count",property = "count"),
            @Result(column = "author",property = "author"),
            @Result(column = "book_sort_id",property = "bookSortName",
                    one = @One(select = "com.tsxy.mapper.BookSortMapper.getNameById"))
    })
    List<BookDto> getAll(@Param("name") String name,@Param("author") String author,@Param("begin") Integer begin,@Param("size") Integer end);

    @Select({"select count(*) from used_book"})
    Integer count();



}
